/**
 * @param {number} num
 * @return {boolean}
*/
var checkPerfectNumber = function(num) {
  if(num == 1) return false;
  let set = new Set();
  set.add(1);
  for(let i = 2; i <= num / 2; i++) {
    if(num % i == 0) {
      set.add(i);
    }
  }
  let arr = [...set];
  return num == arr.reduce((preValue, nowValue) => {
    return preValue + nowValue;
  });
};
let num = 28;
console.log(checkPerfectNumber(num));
num = 7;
console.log(checkPerfectNumber(num));
